<%@ page pageEncoding="UTF-8"%>
<html>
<head>
	<title>资源管理</title>
</head>
<body>
	<h3>资源管理</h3>
<div style = "background: url(../images/menuBg.png) repeat fixed; height:420px">
	<form id="form">
		<input type="hidden" name="roleId" value="${sysrole.id}"/>
		<input type="hidden" name="resources" id="resources"/>
		<div class="content_row">
			<span class="row"><label>名称：</label>${sysrole.name}</span>
			<span class="row"><label>备注：</label>${sysrole.remark}</span>
		</div>
		<div class="content_row content_row_btn">
			<a href="javascript:void(0)" onclick="grant();" class="commonbtn">保存</a>
			<a href="javascript:void(0)" onclick="openUrl('/user/listSysroleView.do');" class="commonbtn">返回</a>
		</div>
	</form>
	<table id="datagrid"></table>
</div>
<script type="text/javascript">
$(function(){
	var roleId = '${sysrole.id}';
	$('#datagrid').treegrid({
	    url:'/user/listGrantResource.do?roleId=' + roleId,
	    rownumbers:true,
	    treeField:'name',
	    idField:'id',
		singleSelect: false,
	    columns:[[
	        {field:'id',title:'ID',width:80,checkbox:true},
	        {field:'name',title:'名称',width:150,align:'left'},
	        {field:'url',title:'路径',width:150,align:'left'},
	        {field:'ismenu',title:'是否菜单',width:100}
	    ]],
		onLoadSuccess:function(row,data){
			if(data){
				checkRow(data.rows);
	    	}
		}                
	});
	//设置回车提交
	enterSubmit('querySubmit');
});

function checkRow(rows){
	$.each(rows, function(index, item){
    	if(item.roleId){
    		$('#datagrid').treegrid('checkRow', item.id);
    	}
    	if(item.children){
    		checkRow(item.children);
    	}
	});
}

function grant(){
	var rows = $('#datagrid').treegrid('getChecked');
	var resources = '';
	for(var i=0;i < rows.length;i++){
		var row = rows[i];
		resources += row.id + ',';
	}
	$('#resources').val(resources);
	submitForm('/user/grant.do','/user/listSysroleView.do');
}
</script>
</body>
</html>
